﻿using System;
using UnityEngine;
using UnityEngine.Events;

namespace Valve.VR.InteractionSystem
{
	// Token: 0x0200060F RID: 1551
	[RequireComponent(typeof(Interactable))]
	public class HapticRack : MonoBehaviour
	{
		// Token: 0x0600275E RID: 10078 RVA: 0x000E5EE0 File Offset: 0x000E40E0
		private void Awake()
		{
			if (this.linearMapping == null)
			{
				this.linearMapping = base.GetComponent<LinearMapping>();
			}
		}

		// Token: 0x0600275F RID: 10079 RVA: 0x000E5F00 File Offset: 0x000E4100
		private void OnHandHoverBegin(Hand hand)
		{
			this.hand = hand;
		}

		// Token: 0x06002760 RID: 10080 RVA: 0x000E5F0C File Offset: 0x000E410C
		private void OnHandHoverEnd(Hand hand)
		{
			this.hand = null;
		}

		// Token: 0x06002761 RID: 10081 RVA: 0x000E5F18 File Offset: 0x000E4118
		private void Update()
		{
			int num = Mathf.RoundToInt(this.linearMapping.value * (float)this.teethCount - 0.5f);
			if (num != this.previousToothIndex)
			{
				this.Pulse();
				this.previousToothIndex = num;
			}
		}

		// Token: 0x06002762 RID: 10082 RVA: 0x000E5F60 File Offset: 0x000E4160
		private void Pulse()
		{
			if (this.hand && this.hand.controller != null && this.hand.GetStandardInteractionButton())
			{
				ushort durationMicroSec = (ushort)UnityEngine.Random.Range(this.minimumPulseDuration, this.maximumPulseDuration + 1);
				this.hand.controller.TriggerHapticPulse(durationMicroSec, EVRButtonId.k_EButton_Axis0);
				this.onPulse.Invoke();
			}
		}

		// Token: 0x04002761 RID: 10081
		[Tooltip("The linear mapping driving the haptic rack")]
		public LinearMapping linearMapping;

		// Token: 0x04002762 RID: 10082
		[Tooltip("The number of haptic pulses evenly distributed along the mapping")]
		public int teethCount = 128;

		// Token: 0x04002763 RID: 10083
		[Tooltip("Minimum duration of the haptic pulse")]
		public int minimumPulseDuration = 500;

		// Token: 0x04002764 RID: 10084
		[Tooltip("Maximum duration of the haptic pulse")]
		public int maximumPulseDuration = 900;

		// Token: 0x04002765 RID: 10085
		[Tooltip("This event is triggered every time a haptic pulse is made")]
		public UnityEvent onPulse;

		// Token: 0x04002766 RID: 10086
		private Hand hand;

		// Token: 0x04002767 RID: 10087
		private int previousToothIndex = -1;
	}
}
